package com.fast.model.result.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author: hujunwei
 */
@ApiModel(value = "Result", description = "返回结果类")
@Data
public class R<T> {
    @ApiModelProperty(name = "code", value = "状态码", example = "")
    private Integer code;

    @ApiModelProperty(name = "msg", value = "状态信息", example = "" + Msg.OK)
    private String msg;

    @ApiModelProperty(name = "data", value = "返回数据")
    private T data;

    public R(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = (T) data;
    }

    // 默认返回成功状态码，数据对象
    public R(Object data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
        this.data = (T) data;
    }

    // 返回指定状态码，数据对象
    public R(StatusCode statusCode, Object data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = (T) data;
    }

    // 只返回状态码
    public R(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = null;
    }
}
